package com.tfy.liquor.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.tfy.liquor.bean.MyPage;
import com.tfy.liquor.bean.UserPriseRecords;
import com.tfy.liquor.dao.UserPriseRecordsDao;
import com.tfy.liquor.service.UserPriseRecordsService;
import com.tfy.liquor.util.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;

@Service
public class UserPriseRecordsServiceImpl implements UserPriseRecordsService {
    @Autowired
    private UserPriseRecordsDao userPriseRecordsDao;

    // 添加数据
    @Override
    public Boolean addUserPriseRecords(UserPriseRecords userPriseRecords) {
        // 获取当前时间
        userPriseRecords.setCreateTime(DateUtil.getNowDateTime());
        return userPriseRecordsDao.addUserPriseRecords(userPriseRecords) > 0;
    }

    // 获取流水记录
    @Override
    public MyPage getUserPriseRecords(Integer pageNum, Integer pageSize, UserPriseRecords userPriseRecords) {
        // 如果传入的参数是负数，则默认为1
        pageNum = Math.max(pageNum, 1);
        pageSize = pageSize < 1 ? 10 : pageSize;
        PageHelper.startPage(pageNum, pageSize);
        ArrayList<UserPriseRecords> list = userPriseRecordsDao.getUserPriseRecords(userPriseRecords);
        // 可以将结果转换为 Page ,
        return new MyPage((Page) list);
    }
}
